<?php

namespace app\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Base extends Model
{
    /**
     * 仓库
     * @return \Illuminate\Support\Collection
     */
    static public function storehouse()
    {
        $list = DB::table('storehouse_master')->select('storehouse_id', 'storehouse_name')->get();
        return $list;
    }

    /**
     * 产品分类
     * @return \Illuminate\Support\Collection
     */
    static public function category()
    {
        $list = DB::table('category_master')->select('category_id', 'category_name','category_code')->get();
        return $list;
    }

    /**
     * 产品
     * @return \Illuminate\Support\Collection
     */
    static public function goods(){
        $list = DB::table('goods_master')->select('goods_id', 'goods_name','goods_code')->get();
        return $list;
    }

    /**
     * 公司信息
     * @return \Illuminate\Support\Collection
     */
    static public function companys(){
        $list = DB::table('corp_master')->select('corp_id', 'corp_name','corp_adress')->get();
        return $list;
    }

    /**
     * 获取公司的详情
     * @param int $id
     *
     * @return Model|null|object|static
     */
    static public function getCorpInfo($id= 1){
        $list = DB::table('corp_master')->where('corp_id','=',$id)->first();
        return $list;
    }

    /**
     * 店铺信息
     * @return \Illuminate\Support\Collection
     */
    static public function shops(){
        $list = DB::table('shop_master')->select('shop_id', 'shop_name','shop_adress')->get();
        return $list;
    }

    /**
     * 尺寸
     * @return array
     */
    static public function size(){
        $list = trans('symessages.goods_size');
        $data = [];
        $i = 1;
        foreach ($list as $value){
            $data[$i] = $value;
            $i++;
        }
        return $data;
    }

    /**
     * 颜色
     * @return array
     */
    static public function colors(){
        $list = trans('symessages.goods_color');
        $data = [];
        $i = 1;
        foreach ($list as $value){
            $data[$i] = $value;
            $i++;
        }
        return $data;
    }


    /**
     * 供应商订单列表
     * @return \Illuminate\Support\Collection
     */
    static public function suppiler_order(){
        $list = DB::table('suppiler_order')->where('state','=',0)->select('order_id','create_time','num')->groupBy(['order_id'])->orderBy('create_time','desc')->get();
        return $list;
    }

    /**
     * 零售商/用户订单列表
     * @return \Illuminate\Support\Collection
     */
    static public function user_order(){
        $list = DB::table('user_order')->where('deliver_state','=',0)->orderBy('create_time','desc')->get();
        return $list;
    }

    /**
     * 供应商管理
     * @return \Illuminate\Support\Collection
     */
    static public function supplier_master(){
        $list = DB::table('supplier_master')->where('delete_flg','=',1)->select('supplier_id','supplier_name')->groupBy(['supplier_id'])->get();
        return $list;
    }

}
